﻿--[[
   @brief    frame_bottom logic for  mianframe right bottom
   @author   harleyxwang
   @version  1.0
   @date     2016-09-13
--]]

frame_bottom_control =
{
    init = function()
        base_utility.log("frame_bottom_control.init called");
        ierd_tgp.tpf_ui.Require("frame_bottom\\plugin_tool_simple_panel.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\plugin_tool_panel.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\model.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\view.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\state_operation_panel.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\gift_op_panel.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\gift_white_list.lua");
        ierd_tgp.tpf_ui.Require('game_library\\control.lua');
        ierd_tgp.tpf_ui.Require("frame_bottom\\rail_branch.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\select_zone_list.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\isp_menu.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\dlc_mgr_view.lua");
        ierd_tgp.tpf_ui.Require("frame_bottom\\wg_frame_bottom\\wg_frame_bottom_control.lua");

        comm_center.reg_service("i_service_downlaod_game", "frame_bottom_control.handle_download_game");
        -- 模拟点击底栏右侧按钮
        comm_center.reg_service("i_service_simulate_click_right_button",
            "frame_bottom_control.handle_simulate_click_right_button");
        comm_center.listen_broadcast("Brdcst_Exit_TGP", frame_bottom_control.on_close_main_wnd);
        comm_center.listen_broadcast("i_broadcast_common_cfg_updated", 
            "frame_bottom_control.on_common_cfg_updated");
        comm_center.reg_service("i_service_allow_continue_operation_game",
            "frame_bottom_control.handle_allow_continue_operation_game");
        comm_center.reg_service("i_service_allow_continue_preupdate_game",
            "frame_bottom_control.handle_allow_continue_predupate_game");
        comm_center.reg_service("i_service_start_game", frame_bottom_control.on_service_start_game);
        comm_center.reg_service("i_service_batch_get_game_state_info",
            frame_bottom_control.on_service_batch_get_game_state_info);
        comm_center.reg_service("i_service_download_game",
            frame_bottom_control.on_service_download_game);
        comm_center.reg_service("i_service_get_game_protocal_check", 
            frame_bottom_control.get_game_protocal_check_state);
        comm_center.reg_service("SvrLua_FrameBottom_RefreshGameState", 
            frame_bottom_control.refresh_game_state);
    end;

    mainframe_show = function(param_tbl)
        if param_tbl ~= nil and param_tbl.isfirst == 1 then
            frame_bottom_view.init();
        end
    end;
    
    show_dlc_mgr = function()
        rail_dlc_manager_view.show();
    end;

    refresh_game_state = function(param)
      if param == nil or param.game_id == nil then
         return;
      end;
      local tbl_data = frame_bottom_control.get_game_and_plugin_state_tbl(param.game_id);
        if true == frame_bottom_control.table_is_empty(tbl_data) then 
            return;
        end
        frame_bottom_view.update_game_or_plugin_state(tbl_data);
    end;

    update_game_state = function(event_id, json_param)
        -- 如果不是当前模块，则直接返回
        local module_id = frame_bottom_model.cur_switch_module_id;
        if nil == module_id or banner_model.GAME_CENTER_GAME_ID == module_id then
            return
        end
        local const_table_param = base_utility.json_to_table(json_param);
        -- const_table_param.game_id = 0,表示所有游戏
        if const_table_param.game_id == nil or banner_model.GAME_CENTER_GAME_ID == const_table_param.game_id then
            return
        end
        -- 增加互斥事件的操作
        -- 设置（取消）相应的互斥量
        if const_table_param.game_id ~= 0 then
            local gl_state = banner_model.get_game_state(const_table_param.game_id);
            if gl_state ~= nil then
                state_operation_panel.set_operation_game_for_other_helper(
                    const_table_param.game_id, gl_state.iState); 
            end
        end

        if 0 ~= const_table_param.game_id and module_id ~= const_table_param.game_id then
            return
        end

        local tbl_data = frame_bottom_control.get_game_and_plugin_state_tbl(module_id);
        if true == frame_bottom_control.table_is_empty(tbl_data) then return end

        frame_bottom_view.update_game_or_plugin_state(tbl_data);
        frame_bottom_control.update_predownload_game_state(tbl_data);
        plugin_tool_panel.handle_tiandao_panel(tbl_data.game.game_id);
        if const_table_param.game_id ~= 0 then
            plugin_tool_panel.on_game_state_update(tbl_data.game);
            plugin_tool_simple_panel.on_game_state_update(tbl_data.game);
        end
    end;

    update_plugin_state = function(event_id, json_str)
        ierd_tgp.tpf_ui.Log("[frame_bottom_control]update_plugin_state,json_str="..json_str);
        local params = base_utility.json_to_table(json_str);
        if params.game_id == nil or 0 == params.game_id or
            banner_model.GAME_CENTER_GAME_ID == params.game_id then
            return
        end

        -- 如果不是当前模块，则直接返回
        local module_id = frame_bottom_control.get_current_select_module();
        if module_id ~= params.game_id then return end

        local plugin_state_info = banner_model.get_plugin_state(module_id);
        if plugin_state_info == nil then return end

        local tbl_data = frame_bottom_control.get_game_and_plugin_state_tbl(module_id);
        if true == frame_bottom_control.table_is_empty(tbl_data) then return end
       
        frame_bottom_view.update_game_or_plugin_state(tbl_data);
    end;

    update_game_servers = function(event_id, json_str)
        local params = base_utility.json_to_table(json_str);
        if (params == nil) then return end
        local game_id = frame_bottom_control.get_current_select_module();
        if nil == game_id or banner_model.GAME_CENTER_GAME_ID == game_id then
            return
        end
        -- "0" 表示所有的游戏
        if 0 == params.game_id or game_id == params.game_id then
            ierd_tgp.tpf_ui.Log("[frame_bottom_control]update_game_servers, game_id="..game_id);
            frame_bottom_control.update_game_servers_info_helper(game_id);
        end            
    end;

    update_game_servers_info_helper = function(game_id)
        ierd_tgp.tpf_ui.Log("[frame_bottom_control]update_game_servers_info_helper,game_id="..game_id);

        local game_servers_table = {};
        game_servers_table.game_id = game_id;

        local game_servers = banner_model.get_game_servers(game_id);
        if game_servers ~= nil then
            game_servers_table.server_count = game_servers.server_count;
            game_servers_table.selleted = game_servers.selleted;
            game_servers_table.net_mode = game_servers.net_mode;
        else
            game_servers_table.server_count = 0;
            game_servers_table.selleted = 0;
            game_servers_table.net_mode = 0;
        end

        game_servers_table.servers = {};
        local count = game_servers_table.server_count;
        local acce_module =
            base_utility.get_component_adapter("IAccelerate_module",
                "ierd_tgp.accelerate_module.GetAcceModule();");
        while (count > 0) do
            local real_ping_val = -1;
            if acce_module ~= nil then
                real_ping_val = acce_module:get_real_ping(game_id, game_servers.selleted);
            end;

            table.insert(game_servers_table.servers, {
                id = game_servers.servers[count - 1].id;
                name = game_servers.servers[count - 1].name;
                need_update = game_servers.servers[count - 1].need_update;
                pre_update = game_servers.servers[count - 1].pre_update;
                state = game_servers.servers[count - 1].state;
                acce_info = {
                    valid = game_servers.servers[count - 1].acce_info.valid;
                    global_acce_enabled = game_servers.servers[count - 1].acce_info.global_acce_enabled;
                    acce_mode = game_servers.servers[count - 1].acce_info.acce_mode;
                    acce_state = game_servers.servers[count - 1].acce_info.acce_state;
                    decision_code = game_servers.servers[count - 1].acce_info.decision_code;
                    direct_delay = game_servers.servers[count - 1].acce_info.direct_delay;
                    direct_lost = game_servers.servers[count - 1].acce_info.direct_lost;
                    proxy_delay = game_servers.servers[count - 1].acce_info.proxy_delay;
                    proxy_lost = game_servers.servers[count - 1].acce_info.proxy_lost;
                    delay_down = game_servers.servers[count - 1].acce_info.delay_down;
                    lost_down = game_servers.servers[count - 1].acce_info.lost_down;
                    direct_delay_raw = game_servers.servers[count - 1].acce_info.direct_delay_raw;
                    proxy_delay_raw_t1 = game_servers.servers[count - 1].acce_info.proxy_delay_raw_t1;
                    proxy_delay_raw_t2 = game_servers.servers[count - 1].acce_info.proxy_delay_raw_t2;
                    real_ping = real_ping_val;
                };
             });
            count = count - 1;
        end;
        frame_bottom_view.update_game_servers_info(game_servers_table);
    end;
    -- 给页面返回游戏和插件的状态信息
    get_game_and_plugin_state = function(event_id, json_str)
        local params = base_utility.json_to_table(json_str);
        local module_id = nil;
        if params ~= nil and params.callback_func ~= nil and params.callback_func ~= "" then
            if params.module_id ~= nil then
                module_id = tonumber(params.module_id);
            end

            local tbl_data = frame_bottom_control.get_game_and_plugin_state_tbl(module_id);
            if true == frame_bottom_control.table_is_empty(tbl_data) then return end
           
            local game_and_plugin_json = base_utility.table_to_json(tbl_data);
            web_utility.lua_call_js_ex(params.callback_func, game_and_plugin_json, CID_MAINFRAME_QBWEB);
        end
    end;
    -- 获取游戏状态的优先级
    get_game_state_priority = function(state_value, game_id)
        local game_lib =
        base_utility.get_component_adapter("IGame_library",
            "ierd_tgp.game_library.Get_game_library_adapter();");

        if nil == game_lib then
            return 0;
        end

        local channel = game_lib:get_game_distribution_channels(game_id);

        if banner_model.is_netbar == 1 and 
            banner_model.distribution_channels.CHANNELS_RAIL ~= channel and
            state_value == ierd_tgp.game_library.GAME_STATE_NOT_INSTALLED then
            state_value = ierd_tgp.game_library.GAME_STATE_NORMAL;
        end

        return banner_model.get_gamestate_priority(state_value);
 
    end;
    -- 判断是否提示联系网管
    need_contact_netbar_manager = function(game_id)
        if game_id == nil then
            return false;
        end
        if banner_model.is_netbar ~= 1 then
            return false;
        end
        local base_info = banner_model.get_game_base_info(game_id);
        if base_info == nil then
            return false;
        end
        local game_state = banner_model.get_game_state(game_id);
        if game_state.iState == ierd_tgp.game_library.GAME_STATE_NORMAL or
           game_state.iState == ierd_tgp.game_library.GAME_STATE_RUNNING then
           return false;
        end
        local param = {
            first_line = LoadStr(ID_NO_GAME_INSTALL_TIP),
            icon = "ONEIMAGE:bottom_bar\\tips_icon\\red_icon.png;Stretch;0;",
        }
        if base_info.banner_icon_url ~= nil then
            param.icon = "ONEIMAGE:bottom_bar\\tips_icon\\yellow_icon.png|"..base_info.banner_icon_url..";Stretch;0";
        end
        event_center.send_event(sub_account_login_event.SUB_ACCOUNT_SHOW_TIPS, 
            base_utility.table_to_json(param));
        return true;
    end;
    -- 给页面返回游戏服务器状态
    get_server_state = function(game_id)
        if game_id ~= nil and game_id ~= 0 then      
            frame_bottom_control.update_game_servers_info_helper(game_id);
        end
    end;
  
    -- 启动游戏
    launch_game = function(game_id, server_id)
        ierd_tgp.tpf_ui.Log("[frame_bottom_control]launch_game, game_id="..game_id..
                            ",server_id="..server_id);
        if game_id == nil or server_id == nil then return end
       
        frame_bottom_control.excute_game_act(GameActions.kStartGame, 
            tonumber(game_id), tonumber(server_id));
    end;
    -- 安装游戏
    install_game = function(game_id_param)
        if game_id_param == nil then return end
        local game_id = tonumber(game_id_param);
        if game_id == 0 or banner_model.GAME_CENTER_GAME_ID == game_id then
            return
        end
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib ~= nil then
            game_lib:install_game(game_id);
        end
    end;
    -- 更新游戏 
    update_game = function(game_id_param, server_id_param)
        if game_id_param == nil then return end
        local game_id = tonumber(game_id_param);
        if game_id == 0 or banner_model.GAME_CENTER_GAME_ID == game_id then
            return
        end

        local server_id = 0;
        if server_id_param ~= nil then
            server_id = tonumber(server_id_param);
        end
        local action_info = { game_id_ = game_id, zone_id_ = server_id, version_ = "", uid_ = 0 };
        local json_str = base_utility.table_to_json(action_info);
        local server = banner_model.get_server_by_zoneid(game_id, server_id);
        if server ~= nil and server.pre_update == true then
            event_center.send_event(popup_wnd_event.PRE_UPDATE_GAME, json_str);
        else
            local game_lib =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
            game_lib:update_game(game_id, server_id, ierd_tgp.game_library.LAUNCH_OP_FROM_LANDING_PAGE);
        end;
    end;
    -- 更新插件
    update_plugin = function(game_id_param)
        if game_id_param == nil then return end
        local game_id = tonumber(game_id_param);
        if game_id == 0 or banner_model.GAME_CENTER_GAME_ID == game_id then
            return
        end

        local plugin_mgr =
            base_utility.get_component_adapter("IPlugin_mgr",
                "ierd_tgp.tgp_plugin.GetPluginMgrModule();");
        if plugin_mgr ~= nil then
            plugin_mgr:UpdatePlugin(game_id);
        end
    end;

    check_update = function(json_str)
        local table_param = base_utility.json_to_table(json_str);
        if table_param ~= nil and table_param.game_id ~= nil 
            and table_param.callback_func ~= nil then
            local module_id = tonumber(table_param.game_id);
            local tbl_data = frame_bottom_control.get_game_and_plugin_state_tbl(module_id);
            if true == frame_bottom_control.table_is_empty(tbl_data) then return end
            local game_and_plugin_json = base_utility.table_to_json(tbl_data);
            web_utility.lua_call_js_ex(table_param.callback_func, game_and_plugin_json, CID_MAINFRAME_QBWEB);
        end
    end;

    get_game_anti_cheat_type = function(game_id)
        base_utility.log(string.format("[frame_bottom]get_game_anti_cheat_type, game id:%d", game_id));
        if game_id == 0 or game_id == nil then
            return 0;
        end
        
        local game_cheat_test_lib =
            base_utility.get_component_adapter("IGameCheatTest",
                "ierd_tgp.game_cheat_test.GetGameCheatTestAdapter();");

        if nil == game_cheat_test_lib then
            base_utility.log("[frame_bottom]get_game_anti_cheat_type, game_cheat_test_lib is nil");
            return 0;
        end
        
        local anti_cheat_type = game_cheat_test_lib:GetGameAntiCheatType(game_id);
        if type(anti_cheat_type) == "string" then
            base_utility.log(string.format("[frame_bottom]get_game_anti_cheat_type, anti_cheat_type:%s",
                anti_cheat_type));
          anti_cheat_type = tonumber(anti_cheat_type)
        end
        if anti_cheat_type == nil then
            return 0;
        end
        base_utility.log(string.format("[frame_bottom]get_game_anti_cheat_type, anti_cheat_type:%d",
            anti_cheat_type));
        return anti_cheat_type;
    end;

    get_game_cheat_test_mode = function(game_id)
        base_utility.log(string.format("[frame_bottom]get_game_cheat_test_mode, game id:%d", game_id));
        if game_id == 0 or game_id == nil then
            return 0;
        end
        
        local game_cheat_test_lib =
            base_utility.get_component_adapter("IGameCheatTest",
                "ierd_tgp.game_cheat_test.GetGameCheatTestAdapter();");

        if nil == game_cheat_test_lib then
            return 0;
        end
        
        local check_value = game_cheat_test_lib:GetGameCheatTestMode(game_id);
        return check_value;
    end;

    set_game_cheat_test_mode = function(game_id, value)
        base_utility.log(string.format("[frame_bottom]set_game_cheat_test_mode, game id:%d, value:%d",
            game_id, value));
        if game_id == 0 or game_id == nil then
            return;
        end
        
        local game_cheat_test_lib =
            base_utility.get_component_adapter("IGameCheatTest",
                "ierd_tgp.game_cheat_test.GetGameCheatTestAdapter();");

        if nil == game_cheat_test_lib then
            return;
        end
        
        game_cheat_test_lib:SetGameCheatTestMode(game_id, value);
    end;

    get_game_and_plugin_state_tbl = function(module_id)
        local game_and_plugin_state = {};
        if module_id == nil then return game_and_plugin_state end

        local game_lib =
        base_utility.get_component_adapter("IGame_library",
            "ierd_tgp.game_library.Get_game_library_adapter();");

        if nil == game_lib then
            return game_and_plugin_state;
        end

        if module_id ~= 0 and module_id ~= nil then
            local game_state = banner_model.get_game_state(module_id);
            local plugin_state = banner_model.get_plugin_state(module_id);
            if game_state == nil and plugin_state == nil then
                ierd_tgp.tpf_ui.Log("[frame_bottom_control]get_game_and_plugin_state_tbl is empty, game_id="..module_id, true);
                return game_and_plugin_state;
            end

            local get_cloud_game_cfg_param = {game_id = module_id};
            local cloud_game_cfg = comm_center.call_service("i_service_get_cloud_game_cfg_info",
                                get_cloud_game_cfg_param);
            local is_cloud_game_tmp = false;
            if cloud_game_cfg ~= nil and cloud_game_cfg.get_data ~=nil and
                cloud_game_cfg.get_data == true then
                is_cloud_game_tmp = true;
                 ierd_tgp.tpf_ui.Log("[frame_bottom_control]get_game_and_plugin_state_tbl cloud "
                                     .. "game_id="..module_id, true);
            end;

            game_and_plugin_state.retCode = 0;
            game_and_plugin_state.msg = "";
            game_and_plugin_state.gameid = module_id;
            if game_state ~= nil then
                local extension_game_state = {
                    has_extensions = game_state.extension_game_state.has_extensions,
                    extension_flag = game_state.extension_game_state.extension_flag,
                    iState = game_state.extension_game_state.iState,
                    iSub_state = game_state.extension_game_state.iSub_state,
                };

                game_and_plugin_state.game = {
                    game_id = module_id, status = game_state.iState, mid = game_state.game_id,
                    sub_status = game_state.iSub_state, progress = game_state.iProgress, 
                    size = game_state.iFile_size, left_time = game_state.iRemain_time,
                    priority = frame_bottom_control.get_game_state_priority(game_state.iState, module_id),
                    speed = game_state.iDownload_speed, 
                    update_post_url = game_state.update_post_url,
                    silent_install = game_state.support_silent_install,
                    retCode = game_state.tcls_update_err_code, msg = game_state.szError_msg,
                    iIs_assistant_uin = game_state.iIs_assistant_uin,
                    iSupport_update = game_state.iSupport_update,
                    iAuto_update = game_state.iAuto_update,
                    iIs_hidden = game_state.iIs_hidden,
                    iSupport_preload = game_state.iSupport_preload,
                    iIs_preload = game_state.iIs_preload,
                    iPre_download = game_state.iPre_download,
                    iPre_download_dot = game_state.iPre_download_dot,
                    formal_update_after = game_state.formal_update_after,
                    last_adjust_progress_time = game_state.last_adjust_progress_time,
                    cancel_flag = game_state.cancel_flag,
                    is_show_new = game_state.is_show_new,
                    pre_download_status = game_state.pre_download_status,
                    install_mode = game_state.install_mode,
                    cur_patch_name = game_state.cur_patch_name,
                    custom_text = game_state.custom_text,
                    extension_game_state = extension_game_state,
                    is_cloud_game = is_cloud_game_tmp,
                };
                local channel = game_lib:get_game_distribution_channels(module_id);
                if banner_model.is_netbar == 1 and 
                    banner_model.distribution_channels.CHANNELS_RAIL ~= channel and
                    game_state.iState == ierd_tgp.game_library.GAME_STATE_NOT_INSTALLED then
                    -- 网吧版本未安装游戏只显示“开始游戏”，点击后提示联系网管
                    game_and_plugin_state.game.status = 0;
                end
                -- 优先显示OSS匹配到的版本公告配置
                local update_post_url_cfg = nil;
                local post_data = banner_model.game_version_post_data[game_and_plugin_state.game.game_id];
                local game_update_target_ver = game_state.update_target_ver;
                update_post_url_cfg = 
                    banner_model.handle_oss_version_post(
                        post_data, game_update_target_ver, game_and_plugin_state.game.game_id);
                if update_post_url_cfg ~= nil and update_post_url_cfg ~= "" then 
                    game_and_plugin_state.game.update_post_url = update_post_url_cfg;
                end

            end
            if plugin_state ~= nil then
                game_and_plugin_state.plugin = {
                retCode = 0, msg = "", game_id = module_id, mid = plugin_state.game_id,
                status = plugin_state.status, progress = plugin_state.progress,
                priority = banner_model.get_pluginstate_priority(plugin_state.status),  
            };
            end  
        end
        return game_and_plugin_state;
    end;

    open_game_dir = function(json_str)
        local lua_table = base_utility.json_to_table(json_str);
        if lua_table == nil or lua_table.game_id == nil then return end
        local game_id = tonumber(lua_table.game_id);
        if game_id == 0 or banner_model.GAME_CENTER_GAME_ID == game_id then
            return
        end
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib ~= nil then
             game_lib:open_game_path(game_id);
        end
    end;

    handle_js_game_action = function(func_name, json_str)
        local table_param = base_utility.json_to_table(json_str);
        if table_param ~= nil and table_param.game_id ~= nil then
            local game_id = tonumber(table_param.game_id);
            if game_id == 0 or banner_model.GAME_CENTER_GAME_ID == game_id then
                return
            end
           local game_action = frame_bottom_control.get_game_action_by_func(func_name);
           if game_action ~= nil and game_action ~= GameActions.kUnkown then
               frame_bottom_control.excute_game_act(game_action, game_id);
           end
        end
    end;
    get_game_action_by_func = function(func_name)
        local game_action = GameActions.kUnkown;
        if 'jc_cancel_update_game' == func_name then
            game_action = GameActions.kCancelUpdate;
        elseif 'jc_cancel_update_plugin' == func_name then
            game_action = GameActions.kCancelUpdatePlugin;
        elseif 'jc_cancel_download' == func_name then
            game_action = GameActions.kCancelDownload;
        elseif 'jc_stop_game' == func_name then
            game_action = GameActions.kStopGame;
        elseif 'jc_continue_download_game' == func_name then
            game_action = GameActions.kContinueDownload;
        elseif 'jc_continue_update_game' == func_name then
            game_action = GameActions.kContinueUpdate;
        elseif 'jc_continue_update_plugin' == func_name then
            game_action = GameActions.kContinueUpdatePlugin;
        elseif 'jc_download_game' == func_name then
            game_action = GameActions.kDownloadGame;
        elseif 'jc_pause_download_game' == func_name then
            game_action = GameActions.kPauseDownload;
        elseif 'jc_pause_update_game' == func_name then
            game_action = GameActions.kPauseUpdate;
        elseif 'jc_pause_update_plugin' == func_name then
            game_action = GameActions.kPauseUpdatePlugin;
        end
        return game_action;
    end;

    excute_game_act = function(game_action, game_id, server_id)
        base_utility.log(string.format("excute_game_act, action:%d, game_id, %d",
            game_action, game_id));

        local zone_id = server_id;
        if zone_id == nil then
            zone_id = 0;
        end
        local action_info = {
                  game_id_ = game_id,
                  zone_id_ = zone_id,
                  version_ = 0,
                  uid_ = login_model.main_uin,
                  launch_op_from = ierd_tgp.game_library.LAUNCH_OP_FROM_LANDING_PAGE
              };
        WGGameAction.excute_action(game_action, action_info);
    end; 

    table_is_empty = function(tbl)
        return _G.next(tbl) == nil;
    end;

    open_post = function(json_str)
        local lua_table = base_utility.json_to_table(json_str);
        if lua_table == nil or lua_table.game_id == nil then return end
        local game_id = tonumber(lua_table.game_id);
        if game_id == 0 or banner_model.GAME_CENTER_GAME_ID == game_id then
            return
        end
        local gl_state = banner_model.get_game_state(game_id);
        if gl_state == nil then return end
        local post_url = gl_state.update_post_url;
        if post_url ~= nil then
            web_utility.open_link(post_url);
        end
    end;

    handle_banner_switch = function(event_id, json_str)
        frame_bottom_view.init();
        -- 切换时,隐藏分支切换校验弹框
        event_center.send_event(unlock_branch_event.CLOSE_DLG_EVENT);

        local params = base_utility.json_to_table(json_str);
        local game_id = nil;
        if params ~= nil then
            if params.module_id ~= nil then
                if params.check_attach ~= nil and params.check_attach == 1 and
                   params.attach_info ~= nil and params.attach_info.select_id ~= nil then
                    game_id = tonumber(params.attach_info.select_id);
                else
                    game_id = tonumber(params.module_id);
                end;

                if frame_bottom_model.cur_switch_module_id ~= game_id then
                    frame_bottom_model.reset_frame_bottom_style_status();
                end;

                -- 保存当前选中的模块id
                frame_bottom_model.cur_switch_module_id = game_id;
            end
        end
      
        if game_id == nil then return end
        -- 进行灰度策略判断
        local is_open = frame_bottom_model.is_open_bottom_feature();
        if not is_open then
            frame_bottom_view.hide_bottom();
            return;
        end
        -- step1：获取助手和游戏的状态，根据不同的状态，显示不同的界面
        if not banner_control.is_game_type_item(game_id) then
            -- 隐藏底栏
            frame_bottom_view.hide_bottom();
            return;
        end;

        if nil == frame_bottom_model.is_user_protocol_agree_table then
            frame_bottom_model.get_game_protocol_agree_info();
        end

        -- 微信绑定qq需求
        if game_id == GAME_ID.GAME_ID_LOL or game_id == GAME_ID.GAME_ID_LOL_TEST then
            if not frame_bottom_model.has_get_wechat_bind_flag then
                frame_bottom_control.get_wechat_bind_qq_cfg();
            end
        end

        -- 如果基本信息获取不到，隐藏底栏
        if nil == banner_model.get_game_base_info(game_id) then
            frame_bottom_view.hide_bottom();
            frame_bottom_model.is_game_base_info_nil = true;
            -- frame_bottom_control.send_bottom_bar_state_to_js(game_id, 0);
            TGPLog.LogE("frame_bottom_control", "handle_banner_switch, Game basic info not find, hide bottom view.");
            return;
        end;

        frame_bottom_control.update_bottom_data_helper(game_id);
        frame_bottom_control.on_bottom_refresh(game_id);

        local state = banner_model.get_game_state(frame_bottom_view.current_select_module_id_);
        base_utility.log("[handle_banner_switch]game_id" .. json_str);
        if nil ~= state then
            base_utility.log("[handle_banner_switch]state:" .. tostring(state.iState));
            base_utility.log("[handle_banner_switch]is show plugin:" .. tostring(frame_bottom_view.is_show_plugin_panel()));
            if false == frame_bottom_model.is_all_protocol_agree(frame_bottom_view.current_select_module_id_) 
            and ierd_tgp.game_library.GAME_STATE_NORMAL == state.iState and false == frame_bottom_view.is_show_plugin_panel() then
                base_utility.log("[handle_banner_switch]show tips");
                frame_bottom_view.show_protocol_tips(true, true);
            else
                base_utility.log("[handle_banner_switch]hide tips");
                frame_bottom_view.show_protocol_tips(false, true);
            end
        else
            base_utility.log("[handle_banner_switch]state is null");
        end
    end;

    update_bottom_data_helper = function(game_id)
        if nil == game_id then return end

         -- 显示助手区和区服信息区的状态
        frame_bottom_view.switch_banner_helper(game_id);
        --[[ lcu remove
        if game_id == 26 or game_id == 100026 then -- 针对LOL或LCU，在显示底栏前拉取一次区服信息
            frame_bottom_control.get_server_state(game_id); 
        end
        ]]
        -- step2：底图颜色的变化
        --frame_bottom_view.set_bottom_background(game_id);
        frame_bottom_view.show_bottom();
        local tbl_data = frame_bottom_control.get_game_and_plugin_state_tbl(game_id);
        frame_bottom_view.update_game_or_plugin_state(tbl_data);
        -- 再次设置底图的颜色
        --frame_bottom_view.set_bottom_background(game_id);
        -- step3：拉取区服信息，展示区别界面
        frame_bottom_control.get_server_state(game_id);
         -- 给launch发送底栏已经显示的通知
        comm_center.send_broadcast('i_broadcast_on_bottom_bar_show', {game_id = game_id});
        frame_bottom_view.move_bottom_dlg();
        frame_bottom_view.refresh_bottom_area(nil);

        -- frame_bottom_control.send_bottom_bar_state_to_js(game_id, 1);
    end;

    open_social_panel = function(event_id, json_str)
        local param_table = base_utility.json_to_table(json_str);
        if param_table ~= nil and param_table.show ~= nil then
           frame_bottom_view.refresh_bottom_area(param_table.show);
        end
    end;

    handle_branch_list_show = function(event_id, json_str)
        local params = base_utility.json_to_table(json_str);
        local game_id = nil;
        if params ~= nil then
            if params.game_id ~= nil then
                game_id = tonumber(params.game_id);
            end
        end

        frame_bottom_view.handle_branch_list_show(event_id, json_str);
    end;
    
    handle_update_branch_info = function(event_id, json_str)
        local params = base_utility.json_to_table(json_str);
        local game_id = nil;
        if params ~= nil then
            if params.game_id ~= nil then
                game_id = tonumber(params.game_id);
            end
        end
        -- 如果是当前gameid.则更新UI.
        if frame_bottom_view.current_select_module_id_ == game_id then
            frame_bottom_view.handle_update_branch_info(event_id, json_str);
        end
    end;
    
    -- 切换为异步
    switch_branch = function(game_id, branch_id)
        if type(branch_id) == "string" then
          branch_id = tonumber(branch_id)
        end
        if type(game_id) == "string" then
          game_id = tonumber(game_id)
        end
        if game_id == nil or game_id == 0 or branch_id == nil then
          base_utility.log("[frame_bottom]switch_branch nil");
          return
        end
        local info = frame_bottom_model.get_branch_info(game_id,branch_id);
        if info == nil then
          base_utility.log("[frame_bottom]info nil");
          return
        end
        
        if info.cur_branch_id == branch_id then
          base_utility.log("[frame_bottom]same branchid");
          return
        end

        local real_switch_branch = function()
            frame_bottom_model.switch_branch(game_id,branch_id);
        end

        local data ={ branch_info = info, callback = real_switch_branch};
        event_center.send_event(unlock_branch_event.ASYNC_CHECK_EVENT, data);
    end;

    handle_social_panel_on_show = function()
        frame_bottom_view.on_mainframe_position_change(); 
    end;

    switch_to_helper_page = function (event_id, json_str)
        if nil == json_str then
            return;
        end;
        local table_data = base_utility.json_to_table(json_str);

        local game_id = nil;
        if nil ~= table_data and nil ~= table_data.game_id then
            game_id = tonumber(table_data.game_id);
        end;

        local ret_code = 0;
        if nil ~= table_data and nil ~= table_data.ret_code then
            ret_code = tonumber(table_data.ret_code);
        end;

        local plugin_state = banner_model.get_plugin_state(game_id);
        if plugin_state ~= nil then
            if ret_code == 0 then
                state_operation_panel.set_helper_area_enable_state(TRUE);
            else
                -- 助手启动失败
                base_utility.log(string.format("[frame_bottom]start plugin helper fail, game id:%d", game_id));
                state_operation_panel.set_helper_area_enable_state(FALSE);
            end;
        else
            -- 无插件的情况
            state_operation_panel.set_helper_area_enable_state(TRUE);
        end
    end;

    --[[ lcu remove
    -- special for lol lcu version
    get_lol_version_info = function()
        local lol_lcu_table = {};
        local game_lib = base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();"); 
        if nil ~= game_lib then
            local lcu_state = ierd_tgp.game_library.LCUState:new();
            game_lib:GetLCUState(lcu_state);
            lol_lcu_table.air_ava = lcu_state.air_available;
            lol_lcu_table.lcu_ava = lcu_state.lcu_available;
            lol_lcu_table.is_lcu = lcu_state.using_lcu;
            lol_lcu_table.is_lcu_merge_air = lcu_state.is_lcu_merge_air;
            lol_lcu_table.is_lcu_full = lcu_state.is_lcu_full;
            lol_lcu_table.is_open_fallback = lcu_state.is_open_fallback;
            lol_lcu_table.is_lcu_server_launch = lcu_state.is_lcu_server_launch;

            -- 【策略改变废弃】7.4版本回退开关设置 针对只安装7.4版本 调整启动按钮
            -- 未开启回退：灰度大区支持air和lcu，非灰度只lcu。开启回退：全部大区支持air和lcu
            -- last update：
            if lol_lcu_table.lcu_ava == false  and lol_lcu_table.is_lcu_merge_air == true then 
                if lol_lcu_table.is_open_fallback == false then --版本回退未开启 
                    if lol_lcu_table.is_lcu_server_launch == true then -- 选择非灰度大区[大区id未在areaLCU中配置] -- 默认只能进LCU，不显示按钮切换
                        lol_lcu_table.lcu_ava = true -- 假装LCU独立客户端可用
                        lol_lcu_table.is_lcu = true -- lcu可用
                        lol_lcu_table.air_ava = false 
                    else
                     -- 未开启回退，且选择灰度大区：支持双端启动
                        lol_lcu_table.air_ava = true
                        lol_lcu_table.lcu_ava = true 
                        if lcu_state.selected_ver == 1 then -- 默认显示上次选择的版本
                            lol_lcu_table.is_lcu = true
                        else
                            lol_lcu_table.is_lcu = false
                        end
                    end
                else 
                    -- 开启回退，全部大区支持双端启动
                    lol_lcu_table.air_ava = true
                    lol_lcu_table.lcu_ava = true -- 默认使用新客户端
                    if lcu_state.selected_ver == 1 then
                        lol_lcu_table.is_lcu = true
                    else
                        lol_lcu_table.is_lcu = false
                    end
                end
            end
            --LCU独立版本存在，灰度版本存在，当前选区在灰度版本中是非灰度大区（支持LCU启动），关闭版本切换
            if lol_lcu_table.lcu_ava == true  and lol_lcu_table.is_lcu_merge_air == true and lol_lcu_table.is_lcu ~= true then
                if lol_lcu_table.is_open_fallback == false then
                    if lol_lcu_table.is_lcu_server_launch == true then
                        lol_lcu_table.lcu_ava = true -- 假装LCU独立客户端可用
                        lol_lcu_table.is_lcu = true -- lcu可用
                        lol_lcu_table.air_ava = false -- 只能使用lcu
                    else
                        lol_lcu_table.lcu_ava = true -- lcu可用
                        --lol_lcu_table.is_lcu = true
                        lol_lcu_table.air_ava = true -- air可用
                    end;
                else
                    lol_lcu_table.lcu_ava = true -- lcu可用
                    --lol_lcu_table.is_lcu = true
                    lol_lcu_table.air_ava = true --  air可用
                end;
            end;

            lcu_state:delete();
        end
        return lol_lcu_table;
    end;
    ]]

    --[[ lcu remove
    -- lcu_param: bool类型参数
    switch_game = function(game_id, lcu_param)
        local game_lib = base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib ~= nil and lcu_param ~= nil and game_id ~= nil and game_id == GAME_ID.GAME_ID_LOL then
            local lcu_state = ierd_tgp.game_library.LCUState:new();
            game_lib:GetLCUState(lcu_state);

            if lcu_state.lcu_available == true then
                    game_lib:SetUsingLCU(not lcu_param); -- 切换LCU/Air客户端
            end
            if lcu_state.is_lcu_merge_air == true then
               local ver_fallback_cfg = 1; -- 灰度大区使用默认LCU客户端
               if lcu_param == true then -- 切换成air
                   ver_fallback_cfg = 0;
               end
               game_lib:SetAirFallbackCfg(ver_fallback_cfg); -- 手动选择的客户端
               -- 刷新底栏
               local tbl_data = frame_bottom_control.get_game_and_plugin_state_tbl(game_id);
               if true == frame_bottom_control.table_is_empty(tbl_data) then return end
               frame_bottom_view.update_game_or_plugin_state(tbl_data);
            end

        end
    end;
    ]]

    -- js 回调函数
    on_js_callback = function(event_id, json_param)
        local param = base_utility.json_to_table(json_param);
        local func_name = param.func_name;
        local json = param.json;
        if func_name == "jc_get_download_gift" then
            if frame_bottom_model.is_open_bottom_feature() then
                gift_op_panel.stop_animation(json);
            end
        end;
    end;

--    handle_mainframe_pos_change = function(data)
--        frame_bottom_view.set_bottom_bar_position();
--    end;

    update_predownload_result = function(event_id, json_param)
        local param = base_utility.json_to_table(json_param);
        local preupdate_game_id = 0;
        local preupdate_result = 0;
        if param.game_id ~= nil and param.game_id ~= 0 then
           preupdate_game_id = param.game_id;
        end;
        if param.result ~= nil then
            preupdate_result = param.result;
        end
        if preupdate_game_id ~= 0 and frame_bottom_view.current_select_module_id_ == preupdate_game_id then
            plugin_tool_panel.set_preupdate_result(preupdate_result);
            plugin_tool_simple_panel.set_preupdate_result(preupdate_result);
        end
        if preupdate_game_id ~= 0 then
            state_operation_panel.set_preupdate_mutex(
                preupdate_game_id, false);
        end
    end;

    update_predownload_begin = function(event_id, json_param)
        local param = base_utility.json_to_table(json_param);
        local preupdate_game_id = 0;
        if param.game_id ~= nil and param.game_id ~= 0 then
           preupdate_game_id = param.game_id;
        end;
        if preupdate_game_id ~= 0 and frame_bottom_view.current_select_module_id_ == preupdate_game_id then
            plugin_tool_panel.set_preupdate_btn_state();
            plugin_tool_simple_panel.set_preupdate_btn_state();
        end
    end;

    update_predownload_game_state = function(game_tbl)
        if game_tbl.game == nil then return end

        local has_preupdate = game_tbl.game.iPre_download;
        local formal_update_after = game_tbl.game.formal_update_after;
        if has_preupdate == 1 and formal_update_after > 0 then
            plugin_tool_panel.set_preupdate_btn_state();
            plugin_tool_simple_panel.set_preupdate_btn_state();
        end
    end;

    handle_game_base_info_update_finish = function ()
        if true == frame_bottom_model.is_game_base_info_nil then
            -- 如果切换没有完成，则收到基本信息更新完成的广播后再切换一次
            base_utility.log("[frame_bottom_control]switch_banner_helper", true);
            local game_id = frame_bottom_control.get_current_select_module();
            if game_id == nil then
                base_utility.log("[frame_bottom_control]switch_banner_helper gameid is nil", true);
                return;
            end

            if banner_control.is_game_type_item(game_id) and banner_model.get_game_base_info(game_id) ~= nil then
                frame_bottom_control.update_bottom_data_helper(game_id);
                frame_bottom_model.is_game_base_info_nil = false;
            else
                base_utility.log(string.format("[frame_bottom_control]update_finish,base info is nil, game id:%d", game_id), true);
            end
        end
    end;

    send_bottom_bar_state_to_js = function (game_id, bottom_show_state)
        local callback_func = web_register_center.get_func_by_browser(
            "web_mainframe_comm_listen", CID_MAINFRAME_QBWEB);
        if callback_func ~= nil and callback_func ~= "" then
            local bottom_info = {};
            bottom_info["state"] = bottom_show_state;
            bottom_info["gameid"] = game_id;
            local rsp_data_table = 
                web_utility.notify_event_comm_data("web_mainframe_comm_listen");
            rsp_data_table.data.data = bottom_info;
            rsp_data_table.data.custom_cmd = "update_frame_bottom_state";
            web_utility.lua_call_js_ex(callback_func, 
                base_utility.table_to_json(rsp_data_table), CID_MAINFRAME_QBWEB);
        end
    end;

    is_bottom_bar_show = function()
        return frame_bottom_view.is_bottom_bar_show();
    end;

    handle_download_game = function (data)
        if nil == data or nil == data.game_id then
            return;
        end
        state_operation_panel.download_game_helper(data.game_id);
    end;

    handle_simulate_click_right_button = function (data)
        if nil == data or nil == data.game_id then
            return;
        end

        if 0 == frame_bottom_view.status_operation_id_ then
            return;        
        end

        local state_op_ctn_id = ui_utility.get_ctrl_id_by_path(frame_bottom_view.status_operation_id_, "StateOperationCnt");
        local op_btn_ptr = ui_utility.get_ctrl_ptr_by_path(state_op_ctn_id, "OperationBtn");
        if nil == op_btn_ptr then
            return;
        end

        -- 可见才模拟点击
        if op_btn_ptr:IsVisible() == TRUE then
            frame_bottom_view.on_right_btn_click();
        else
            wg_frame_bottom_view.handle_simulate_click_right_button(data);
        end
    end;

    handle_simulate_click_assist_button = function (data)

        if nil == data or nil == data.game_id then
            return;
        end

        if not frame_bottom_view.is_assistant_visible(data.game_id) then
            return;
        end

        local base_info = banner_model.get_game_base_info(data.game_id);
        if base_info == nil then  
            return;
        end;

        if base_info.type == ierd_tgp.game_library.GAME_LIST_TYPE_CONSOLE then
            plugin_tool_simple_panel.on_cross_setting_btn_click();
        else
            plugin_tool_panel.on_assist_setting_btn_click();
        end

    end;

    get_wechat_bind_qq_cfg = function ()
         -- 先从本地获取
        local config =  frame_bottom_model.get_wechat_bind_config();
        -- 本地没有记录则通过cgi拉取
        if nil == config or 0 == config.exits then
            base_utility.get_accumulate_count(frame_bottom_model.wechat_bind_qq_item, "wx2qq4lol", login_model.main_uin, 
                "frame_bottom_control.on_callback_get_wechat_bind_qq_cfg");
        else 
            frame_bottom_model.has_get_wechat_bind_flag = true;
            frame_bottom_model.need_show_wechat_bind_qq_wnd = false;
        end
    end;

    on_callback_get_wechat_bind_qq_cfg = function(json_str)
        local result_tb = base_utility.json_to_table(json_str);
        if nil == result_tb then
            return;
        end

        base_utility.log(string.format("[frame_bottom_control][on_callback_get_wechat_bind_qq_cfg]json_str:%s", json_str), true);

        if 0 == result_tb.result then
            local list = result_tb.sub_item_list;
            if type(list) ~= "table" or nil == next(list) then  
                frame_bottom_model.need_show_wechat_bind_qq_wnd = true;
            else
                -- 当前的子项不在已读的列表中
                if false == frame_bottom_control.subitem_is_in_list("wx2qq4lol", result_tb.sub_item_list) then
                     frame_bottom_model.need_show_wechat_bind_qq_wnd = true;
                end
            end

            frame_bottom_model.has_get_wechat_bind_flag = true;
        end
    end;

     subitem_is_in_list = function (sub_item, list)
        if nil == list then
            return false;
        end
        local is_in_list = false;
        for k, v in pairs(list) do
            if tostring(v.sub_item) == sub_item and (0 ~= v.is_reported) then
                is_in_list = true;
                break;
            end
        end
        return is_in_list;
    end;

    set_wechat_bind_qq_cfg = function ()
        base_utility.set_accumulate_count(frame_bottom_model.wechat_bind_qq_item, "wx2qq4lol", 1,
                login_model.main_uin, "frame_bottom_control.on_callback_set_wechat_bind_qq_cfg");
        -- 写入本地配置
        frame_bottom_model.save_wechat_bind_config();
        frame_bottom_model.need_show_wechat_bind_qq_wnd = false;
    end;

    on_callback_set_wechat_bind_qq_cfg = function (json_str)
        local result_tb = base_utility.json_to_table(json_str);
        if nil == result_tb then
            return;
        end

        base_utility.log(string.format("[frame_bottom_control][on_callback_set_wechat_bind_qq_cfg]json_str:%s", json_str), true);
    end;
    
    get_current_select_module = function()
        local module_id = banner_view.get_current_select_module();
        local game_id = tonumber(module_id);
        if frame_bottom_model.cur_switch_module_id ~= nil and frame_bottom_model.cur_switch_module_id ~= 0 and 
           frame_bottom_model.cur_switch_module_id ~= game_id then
            game_id = frame_bottom_model.cur_switch_module_id;
        end;
        return game_id;
    end;

    on_bottom_refresh = function(game_id)
        if game_id == nil or tonumber(game_id) == 0 then
            return;
        end;
        
        local attach_info = comm_center.call_service("Svr_CheckHasAttachRel", 
                           {game_id = tonumber(game_id), has_attach = 0, select_id = 0, main_game_id = 0});
        if attach_info == nil or attach_info.has_attach ~= 1 or 
           attach_info.select_id == 0 or attach_info.main_game_id == 0 then
            return;
        end;

        comm_center.call_service("Svr_SetLastSelectInAttachRel", 
                                {game_id = attach_info.main_game_id, select_id = tonumber(game_id)});
        comm_center.call_service("Svr_UpdateUserQualityInfo", {game_id = tonumber(game_id)});
    end;

    on_close_main_wnd = function ()
        frame_bottom_model.save_protocol_agree_tb();
    end;

    on_common_cfg_updated = function ()
       -- 配置更新，则再尝试查询
       base_utility.log("[on_common_cfg_updated]");
    end;

    handle_allow_continue_operation_game = function(param_tbl)
        local bAllow = true;
        if param_tbl ~= nil and param_tbl.game_id ~= nil then
            bAllow = state_operation_panel.is_allow_continue_operation_helper(param_tbl.game_id);
        end
        return {bAllowContinue = bAllow};
    end;

    handle_allow_continue_predupate_game = function(param_tbl)
        local bAllow = true;
        if param_tbl ~= nil and param_tbl.game_id ~= nil then
            bAllow = state_operation_panel.is_allow_continue_preupdate(param_tbl.game_id);
        end
        return {bAllowContinue = bAllow};
    end;
    
    --  有DLC未安装时提示
    show_game_download_dlc_tips = function(event_id, json_str)
        base_utility.log(string.format("[frame_bottom_control][show_game_download_dlc_tips]event_id:%d, json_str:%s", event_id, json_str), true);
        local params = base_utility.json_to_table(json_str);
        plugin_tool_simple_panel.show_game_download_dlc_tips(params.game_id, params.show);
    end;
    
    -- 下载管理器接口
    -- 游戏启动服务接口 -- TODO 游戏状态重新划分归类
    launch_game_for_download_mgr = function(data_in)
        base_utility.log("[frame_bottom][GameDownloadMgr][launch_game_for_download_mgr]");
        if data_in == nil or data_in.game_id == nil then
            base_utility.log("[launch_game_extend] param is nil");
            return;
        end
        local game_id = data_in.game_id;
        local game_state = banner_model.get_game_state(game_id);
        if game_state == nil then
            base_utility.log("[launch_game_extend]get game state failed");
        end

        -- 获取选择的区服：
        local server_id = 0;
        local game_servers = banner_model.get_game_servers(game_id);
        if game_servers ~= nil then
            server_id = game_servers.selleted;
        end

        base_utility.log("[frame_bottom][launch_game_for_download_mgr]game=" 
            .. game_id .. "state" .. game_state.iState .. "server_id" .. server_id);

        if ierd_tgp.game_library.GAME_STATE_NORMAL == game_state.iState  or 
            ierd_tgp.game_library.GAME_STATE_UNKNOWN == game_state.iState then
            -- 启动游戏
            if false == frame_bottom_model.is_all_protocol_agree(game_id) then
                frame_bottom_view.show_contract_no_check_tips(true);
                base_utility.log("[launch_game_extend]check protocol tips");
                -- 启动一个超时定时器
                base_utility.add_interval(
                    "state_operation_panel.handle_show_contact_no_check_tips", 5 * 1000); 
                
                -- 游戏协议未选中, 跳转到游戏助手页, 展示底栏的协议tips
                local req_data = {game_id = game_id};
                comm_center.call_service("i_svr_focus_item", req_data);
                return;
            end
            if frame_bottom_model.is_all_protocol_agree(game_id) then
                frame_bottom_view.show_protocol_tips(false);
            end
            if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                if frame_bottom_control.need_contact_netbar_manager(game_id) == false then
                    base_utility.log("[launch_game_extend]start game");
                    state_operation_panel.StartGame(game_id, server_id);
                end
            end
        else
            base_utility.log(
                "[launch_game_extend] do not allow to start, cur_game_state is invalid");
        end
     end;

     start_task_for_download_mgr = function(data_in)
        base_utility.log("[frame_bottom][GameDownloadMgr][start_task_for_download_mgr]");
        if data_in == nil or data_in.game_id == nil then
            base_utility.log("[start_task_for_download_mgr] param is nil");
            return;
        end
        local game_id = data_in.game_id;
        local game_state = banner_model.get_game_state(game_id);
        if game_state == nil then
            base_utility.log("[start_task_for_download_mgr]get game state failed");
        end
        local report_op_type = "";
        local state_value = game_state.iState;
        local sub_state = game_state.iSub_state;
        if state_value == nil then
            base_utility.log("[start_task_for_download_mgr]state_value is nil");
            return;
        end;

        local use_extension_state = false;
        local extension_state = game_state.extension_game_state.iState;
        local extension_substate = game_state.extension_game_state.iSub_state;
        base_utility.log("[frame_bottom][start_task_for_download_mgr]game=" 
            .. game_id .. ", state=" .. state_value..", extension state=".. extension_state 
            .. "extension substate="..extension_substate);
       if game_state.extension_game_state.has_extensions then
            if state_value == ierd_tgp.game_library.GAME_STATE_NORMAL or
                state_value == ierd_tgp.game_library.GAME_STATE_RUNNING or
                 state_value == ierd_tgp.game_library.GAME_STATE_LAUNCHING or
                  state_value == ierd_tgp.game_library.GAME_STATE_SELECTING_SERVER or
                   state_value == ierd_tgp.game_library.GAME_STATE_SERVER_UNAVAILABLE then
                  state_value = extension_state;
                  sub_state = extension_substate;
                  use_extension_state = true;
            end
        end
        if state_value == ierd_tgp.game_library.GAME_STATE_NEED_UPDATE then
            -- 更新操作
            local pause_status = frame_bottom_model.get_game_update_pause_status(game_id);
            if 0 == pause_status then
                if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                    frame_bottom_control.excute_game_act(
                        GameActions.kUpdateGame, game_id, server_id);
                    report_op_type = "update_game";
                end
            else
                local use_tinysetup = frame_bottom_model.get_game_update_mode(game_id);
                if use_tinysetup ~= 1 then
                    frame_bottom_control.excute_game_act(GameActions.kUpdateGame, game_id);
                else
                    --使用tinysetup的继续更新
                    local param = {};
                    param["game_id"] = game_id;
                    comm_center.call_service("i_service_continue_update_game", param);
                end
                report_op_type = "contiune_update_game";
            end
        elseif state_value == ierd_tgp.game_library.GAME_STATE_UPDATE_FAIL then
            -- 重试更新
            if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                state_operation_panel.update_game_helper(game_id);
                report_op_type = "re_update_game";
            end
        elseif state_value == ierd_tgp.game_library.GAME_STATE_UPDATING then
            -- 游戏更新状态但在等待
            -- 继续更新操作
            if sub_state ~= nil then
            --[[
                if sub_state == ierd_tgp.game_library.GAME_UPDATE_WAIT then
                    base_utility.log("[frame_bottom][GameDownloadMgr][start_task_for_download_mgr]"
                        .. "wait for updating");
                        
                    -- 先置为暂停状态再继续
                    frame_bottom_control.excute_game_act(GameActions.kPauseUpdate, game_id);

                    frame_bottom_control.excute_game_act(GameActions.kUpdateGame, game_id);
                    report_op_type = "continue_download_game";
                elseif sub_state == ierd_tgp.game_library.GAME_UPDATE_DEPOT_WAIT then
                    -- 先置为暂停状态再继续
                    frame_bottom_control.excute_game_act(GameActions.kPauseUpdate, game_id);

                    local param = {};
                    param["game_id"] = game_id;
                    comm_center.call_service("i_service_continue_update_game", param);
                    report_op_type = "contiune_update_game";
                end
            --]]
            base_utility.log("[frame_bottom][GameDownloadMgr][start_task_for_download_mgr]"
                .. "wait for updating, sub_state=" .. sub_state);
                if sub_state == ierd_tgp.game_library.GAME_UPDATE_WAIT or 
                    sub_state == ierd_tgp.game_library.GAME_UPDATE_DEPOT_WAIT then

                    if not use_extension_state then
                        -- 先重置为暂停状态
                        state_value = ierd_tgp.game_library.GAME_STATE_NEED_UPDATE;
                        sub_state = 0;
                    end

                    local pause_status = frame_bottom_model.get_game_update_pause_status(game_id);
                    if 0 == pause_status then
                        if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                            frame_bottom_control.excute_game_act(
                                GameActions.kUpdateGame, game_id, server_id);
                            report_op_type = "update_game";
                        end
                    else
                        local use_tinysetup = frame_bottom_model.get_game_update_mode(game_id);
                        if use_tinysetup ~= 1 then
                            frame_bottom_control.excute_game_act(GameActions.kUpdateGame, game_id);
                        else
                            --使用tinysetup的继续更新
                            local param = {};
                            param["game_id"] = game_id;
                            comm_center.call_service("i_service_continue_update_game", param);
                        end
                        report_op_type = "update_game";
                    end
                end
            end
        elseif state_value == ierd_tgp.game_library.GAME_STATE_DOWNLOADED then
            -- 安装
            if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                frame_bottom_control.excute_game_act(GameActions.kInstallGame, game_id);
                report_op_type = "install_game";
            end
        elseif state_value == ierd_tgp.game_library.GAME_STATE_DOWNLOAD_FAIL then
            -- 重试下载
            if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                state_operation_panel.download_game_helper(game_id);
                report_op_type = "re_download_game";
            end
        elseif state_value == ierd_tgp.game_library.GAME_STATE_BROKEN then
            -- 支持重新下载则下载，否则不处理
            if sub_state_value == 1 then
                -- 重新下载
                -- 先尝试卸载掉旧版本再重新下载
                if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                    local result_info = comm_center.call_service("Svr_UninstallBrokenGame",
                                             {game_id = game_id});
                    if result_info == nil or result_info.can_uninstall == nil or 
                        result_info.can_uninstall ~= 1 then
                        state_operation_panel.download_game_helper(game_id);
                        report_op_type = "re_download_game";
                    else
                        base_utility.log("[start_task_for_download_mgr] uninstall first");
                    end
                end
            else
                base_utility.log(
                "[start_task_for_download_mgr]game_state is brken, and not support redownload");
            end;
            
        elseif state_value == ierd_tgp.game_library.GAME_STATE_NOT_INSTALLED then
            -- 下载游戏
            if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                frame_bottom_control.excute_game_act(GameActions.kDownloadGame, game_id);
                report_op_type = "download_game";
            end
        elseif state_value == ierd_tgp.game_library.GAME_STATE_DOWNLOAD_PAUSED then
            -- 游戏暂停下载状态
            -- 继续下载操作
            if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                frame_bottom_control.excute_game_act(GameActions.kContinueDownload, game_id);
                report_op_type = "continue_download_game";
            end
        elseif state_value == ierd_tgp.game_library.GAME_STATE_DOWNLOADING then
            -- 游戏下载状态但在等待
            -- 继续下载操作
            
            if sub_state ~= nil then 
                base_utility.log("[frame_bottom][GameDownloadMgr][start_task_for_download_mgr]" .. 
                    "wait for downloading, sub_state =" .. sub_state);
                if sub_state == ierd_tgp.game_library.GAME_DOWNLOAD_WAIT then
                    -- 先置为暂停状态再继续
                    -- frame_bottom_control.excute_game_act(GameActions.kPauseDownload, game_id);
                    
                    -- Game_install_state::DOWNLOAD_PAUSED = 2
                    if not use_extension_state then
                        state_value = ierd_tgp.game_library.GAME_STATE_DOWNLOAD_PAUSED;
                        sub_state = ierd_tgp.game_library.GAME_DOWNLOAD_INIT;
                        comm_center.call_service(
                        "Svr_ChangeGameInstallState", {game_id = game_id, install_state = 2});
                    end

                    if game_state.extension_game_state.has_extensions then
                        comm_center.call_service("Svr_ChangeGameInstallSubstate",
                                                { game_id = game_id, install_substate = 258,
                                                  refresh_state = true } );
                    end

                    if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                        frame_bottom_control.excute_game_act(GameActions.kContinueDownload, game_id);
                        report_op_type = "continue_download_game";
                    end
                end
            end
        else
            base_utility.log(
                "[frame_bottom][start_task_for_download_mgr], ignore status" 
                .. tostring(state_value));
        end
     end;

     pause_task_for_download_mgr = function(data_in)
        base_utility.log("[frame_bottom][GameDownloadMgr][pause_task_for_download_mgr]");
        if data_in == nil or data_in.game_id == nil then
            base_utility.log("[pause_task_for_download_mgr] param is nil");
            return;
        end
        local game_id = data_in.game_id;
        local game_state = banner_model.get_game_state(game_id);
        if game_state == nil then
            base_utility.log("[pause_task_for_download_mgr]get game state failed");
        end
        local report_op_type = "";
        local state_value = game_state.iState;
        local extension_state = ierd_tgp.game_library.GAME_STATE_UNKNOWN;
        if game_state.extension_game_state.has_extensions then
            extension_state = game_state.extension_game_state.iState;
        end
        base_utility.log("[frame_bottom][pause_task_for_download_mgr]game=" 
            .. game_id .. "state" .. state_value..", extension state".. extension_state);
        if game_state.extension_game_state.has_extensions and
           state_value ~= ierd_tgp.game_library.GAME_STATE_DOWNLOADING and 
           state_value ~= ierd_tgp.game_library.GAME_STATE_UPDATING then
            state_value = extension_state;
        end
        if state_value == ierd_tgp.game_library.GAME_STATE_DOWNLOADING then
            -- 暂停下载操作
            frame_bottom_control.excute_game_act(GameActions.kPauseDownload, game_id);
            report_op_type = "pause_download_game";
        elseif state_value == ierd_tgp.game_library.GAME_STATE_UPDATING then
            -- 暂停更新
            frame_bottom_control.excute_game_act(GameActions.kPauseUpdate, game_id);
            report_op_type = "pause_update_game";
        end
     end;

     cancel_task_for_download_mgr = function(data_in)
        base_utility.log("[frame_bottom][GameDownloadMgr][cancel_task_for_download_mgr]");
        if data_in == nil or data_in.game_id == nil then
            base_utility.log("[cancel_task_for_download_mgr] param is nil");
            return;
        end
        local game_id = data_in.game_id;
        local game_state = banner_model.get_game_state(game_id);
        if game_state == nil then
            base_utility.log("[cancel_task_for_download_mgr]get game state failed");
        end
        local report_op_type = "";
        local state_value = game_state.iState;
        local extension_state = ierd_tgp.game_library.GAME_STATE_UNKNOWN;
        if game_state.extension_game_state.has_extensions then
            extension_state = game_state.extension_game_state.iState;
        end
        base_utility.log("[frame_bottom][cancel_task_for_download_mgr]game=" 
            .. game_id .. "state" .. state_value..", extension state".. extension_state);
        if game_state.extension_game_state.has_extensions and
           state_value ~= ierd_tgp.game_library.GAME_STATE_DOWNLOADING and 
           state_value ~= ierd_tgp.game_library.GAME_STATE_UPDATING and
           state_value ~= ierd_tgp.game_library.GAME_STATE_DOWNLOAD_PAUSED and
           state_value ~= ierd_tgp.game_library.GAME_STATE_NEED_UPDATE then
            state_value = extension_state;
        end
        if state_value == ierd_tgp.game_library.GAME_STATE_UPDATING then
            -- 取消更新
            frame_bottom_control.excute_game_act(GameActions.kCancelUpdate, game_id);
            report_op_type = "cancel_update_game";
        elseif state_value == ierd_tgp.game_library.GAME_STATE_DOWNLOADING then
            frame_bottom_control.excute_game_act(GameActions.kCancelDownload, game_id);
            report_op_type = "cancel_download_game";
        elseif state_value == ierd_tgp.game_library.GAME_STATE_DOWNLOAD_PAUSED then
            frame_bottom_control.excute_game_act(GameActions.kCancelDownload, game_id); 
            report_op_type = "cancel_download_game";
        elseif state_value == ierd_tgp.game_library.GAME_STATE_NEED_UPDATE then
            local pause_status = frame_bottom_model.get_game_update_pause_status(game_id);
            frame_bottom_control.excute_game_act(GameActions.kCancelUpdate, game_id);
            report_op_type ="cancel_update_game";
        else
            comm_center.call_service("Svr_RemoveTaskFromDownloadMgr", {game_id = game_id});
        end
     end;

    clear_protocol_agree = function(data_in)
        base_utility.log("[frame_bottom][clear_protocol_agree]");
        if data_in == nil or data_in.game_id == nil then
            base_utility.log("[frame_bottom][clear_protocol_agree] param is nil");
            return;
        end
        local game_id = data_in.game_id;
        frame_bottom_model.clear_protocol_agree_by_gameid(game_id);
    end;

    on_service_start_game = function(param_tbl)
        if param_tbl ~= nil then
            local game_id = tonumber(param_tbl.game_id);
            if game_id == nil then
                base_utility.log('[frame_bottom_control]start game, game id invalid.');
                return;
            end;
            local server_id = tonumber(param_tbl.server_id) or 0; 
            if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                if frame_bottom_control.need_contact_netbar_manager(game_id) == false then
                    state_operation_panel.StartGame(game_id, server_id);  
                end
            end
        end
    end;

    on_service_batch_get_game_state_info = function(param_input)
        if param_input ~= nil and param_input.data ~= nil and 
            param_input.data.game_id_list ~= nil and type(param_input.data.game_id_list) == 'table' then
            local rsp_table = web_utility.web_rsp_comm_data(param_input, 0, "");
            rsp_table.data = {};
            local game_lib =
                    base_utility.get_component_adapter("IGame_library",
                        "ierd_tgp.game_library.Get_game_library_adapter();");
            for i, game_id in ipairs(param_input.data.game_id_list) do
                if game_id ~= nil and game_id ~= 0 then
                    local channel = game_lib:get_game_distribution_channels(game_id);
                    local game_state = banner_model.get_game_state(game_id);
                    if game_state ~= nil then
                        -- 修改游戏状态
                        local game_status = 0;
                        if banner_model.is_netbar == 1 and 
                            banner_model.distribution_channels.CHANNELS_RAIL ~= channel and
                            game_state.iState == ierd_tgp.game_library.GAME_STATE_NOT_INSTALLED then
                            -- 网吧版本未安装游戏只显示“开始游戏”，点击后提示联系网管
                            game_status = ierd_tgp.game_library.GAME_STATE_NORMAL;
                        else 
                            game_status = game_state.iState;
                        end
                        local game_state_info = {
                            game_id = game_id,
                            status = game_status,
                            sub_status = game_state.iSub_state,
                        };
                        table.insert(rsp_table.data, game_state_info);  
                    end
                end
            end
            return rsp_table;
        end
    end;

    on_service_download_game = function(param_tbl)
        if param_tbl ~= nil and param_tbl.game_id ~= 0 then
            local game_id = param_tbl.game_id;
            if state_operation_panel.is_allow_continue_operation_helper(game_id) then
                frame_bottom_control.excute_game_act(GameActions.kDownloadGame, game_id);
            end
        end
    end;

    on_download_mgr_mode_change = function(data)
        if nil ~= data then
            if data.is_downloading then
                frame_bottom_control.add_progress_info_transition_timer();
            else
                frame_bottom_control.remove_progress_info_transition_timer();
            end
        end
    end;

    add_progress_info_transition_timer = function()
        state_operation_panel.reset_progress_info_transition();
        base_utility.add_interval("frame_bottom_control.progress_info_transition_timer", 1000);
    end;

    remove_progress_info_transition_timer = function()
        base_utility.remove_interval("frame_bottom_control.progress_info_transition_timer");
        state_operation_panel.reset_progress_info_transition();
        frame_bottom_control.force_update_bottom();
    end;

    force_update_bottom = function()
        if FALSE == frame_bottom_control.is_bottom_bar_show() then
            return;
        end
        local game_id = frame_bottom_control.get_current_select_module();
        frame_bottom_control.update_bottom_data_helper(game_id);
    end;

    progress_info_transition_timer = function()
        if FALSE == frame_bottom_control.is_bottom_bar_show() then
            return;
        end
        if state_operation_panel.tick_progress_info_transition() then
            frame_bottom_control.force_update_bottom();
        end
    end;

    get_game_protocal_check_state = function (param_tbl)
        local is_agree = false;
        if param_tbl ~= nil then
            local game_id = tonumber(param_tbl.game_id);
            if game_id == nil then
                base_utility.log('[frame_bottom_control]get_game_protocal_check_state game id invalid.');
                return;
            end;
            if nil == frame_bottom_model.is_user_protocol_agree_table then
                frame_bottom_model.get_game_protocol_agree_info();
            end
            is_agree = frame_bottom_model.is_all_protocol_agree(game_id);   
        end
        return {protocal_checked = is_agree};
    end;

    handle_update_banner_config = function()
        if frame_bottom_model == nil or frame_bottom_view == nil then
            return;
        end;
        local info = frame_bottom_model.get_game_user_protocol(frame_bottom_view.current_select_module_id_);
        if info == nil or info.protocol_list == nil then
            return;
        end;
        local tips_ptr = ui_utility.get_ctrl_ptr_by_id(frame_bottom_view.user_protocol_tips_);
        if frame_bottom_model.cur_game_ctrl_id_2_prtcl_info ~= nil and
           #frame_bottom_model.cur_game_ctrl_id_2_prtcl_info ~= 0 and
           #frame_bottom_model.cur_game_ctrl_id_2_prtcl_info ~= #info.protocol_list and
           tips_ptr ~= nil and tips_ptr:IsVisible() then
            base_utility.log('[frame_bottom_control]game protocol count change,refresh tips', true);
            frame_bottom_view.show_protocol_tips(true, false);
        end;
    end;
};

frame_bottom_control.init();
